package dbutils

import "database/sql"

func GetRowsMap(rows *sql.Rows) (map[string]string, error) {
	//字段
	cols, err := rows.Columns()
	if err != nil {
		return nil, err
	}
	values := make([]sql.RawBytes, len(cols))
	scans := make([]interface{}, len(cols))
	for i := range values {
		scans[i] = &values[i]
	}
	err = rows.Scan(scans...)
	if err != nil {
		return nil, err
	}
	row := make(map[string]string)
	for j, v := range values {
		key := cols[j]
		row[key] = string(v)
	}
	return row, nil
}
